package com.foxmail.yusp.mycloud;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.ArrayList;

public class MqttHistoryAdapter extends RecyclerView.Adapter<MqttHistoryAdapter.ViewHolder> {
    private ArrayList<String> data;

    public MqttHistoryAdapter(ArrayList<String> data) {
        this.data = data;
    }

    @Override
    public MqttHistoryAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        // Create View
        View v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.adapter_mqtt_history, parent, false);

        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(MqttHistoryAdapter.ViewHolder holder, int position) {
        holder.mTextView.setText(data.get(position));
    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public TextView mTextView;

        public ViewHolder(View v) {
            super(v);
            mTextView = v.findViewById(R.id.txt_row);
        }
    }

    public void add(String row){
        data.add(row);
        this.notifyDataSetChanged();
    }
    //
}
